package com.cn.hotel.servlet.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.*;
import com.cn.hotel.service.*;
import com.cn.hotel.service.impl.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/setOrder")
public class ReservationServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String phone = req.getParameter("phone");
        String inTime = req.getParameter("inTime");
        String outTime = req.getParameter("outTime");
        String roomType = req.getParameter("roomType");
        String opinion = req.getParameter("opinion");
        OrderModel orderModel = new OrderModel();
        orderModel.setUsername(username);
        orderModel.setPhone(phone);
        orderModel.setCheckInTime(inTime);
        orderModel.setCheckOutTime(outTime);
        orderModel.setRoomType(roomType);
        orderModel.setOpinion(opinion);
        IOrderService iOrderService = new OrderServiceImpl();
        int count = iOrderService.add(orderModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
